﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Maticsoft.Web
{
    public partial class UserIdentity : PageBaseMember
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Check();

            if (!IsPostBack)
            {
                GetData();
            }
        }

        protected void GetData()
        {
            BLL.Members meBLL = new BLL.Members();
            Model.Members meModel = meBLL.GetModel(int.Parse(this.UserId));
            if (meModel.Status == 4)
            {
                ltlStatusName.Text = "认证失败";
            }
            else if (meModel.Status == 3)
            {
                ltlStatusName.Text = "已认证";
                imgZheng.Src = "~/uploadpic/" + meModel.IdentityCardPic1;
                imgFan.Src = "~/uploadpic/" + meModel.IdentityCardPic2;
                btnSave.Visible = false;
            }
            else if (meModel.Status == 2)
            {
                ltlStatusName.Text = "认证中";
            }
            else
            {
                ltlStatusName.Text = "未认证";
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            BLL.Members meBLL = new BLL.Members();
            Model.Members meModel = meBLL.GetModel(int.Parse(this.UserId));
            ImageUpload img = new ImageUpload();
            img.SavePath = "~/uploadpic/";
            img.FormFile = File1;
            img.Upload();
            if (img.Error == 0)
            {
                meModel.IdentityCardPic1 = img.OutFileName;
            }
            img.SavePath = "~/uploadpic/";
            img.FormFile = File2;
            img.Upload();
            if (img.Error == 0)
            {
                meModel.IdentityCardPic2 = img.OutFileName;
            }
            meModel.Status = 2;
            meModel.UpdateTime = DateTime.Now;
            meBLL.Update(meModel);
            GetData();
        }
    }
}